<?php
require("includes/constantesMvial.php");

function marcas($cantidad){
	$cantidad = $cantidad - 1;
	$tabla = '<table cellpadding="0" cellspacing="0" width="100%" align="center" border="0" class="tabTablefull">';
	$query = "SELECT * FROM mvial_category WHERE show_in_frontpage = 1 AND cat_fatherid = 1000 ORDER BY order_number limit " . $cantidad . ", 1";
	$sql=mysql_query($query);
	while($rg=mysql_fetch_object($sql)) {
		
		$tabla .= "<tr><td>";
		$contador = 0;
		$queryp = "SELECT A.*, B.marca FROM cat_marca AS A, marca AS B WHERE (A.cat_id = " . $rg->cat_id . " OR A.cat_id IN (SELECT cat_id FROM mvial_category WHERE cat_fatherid = " . $rg->cat_id . ")) AND A.id_marca = B.id GROUP BY marca ORDER BY B.marca";
		$sqlp=mysql_query($queryp);
		while($rgp=mysql_fetch_object($sqlp)) {
		$contador = $contador + 1;
		if($contador == 1) $tabla .= '<img src=/catimages/'.$rg->cat_image.' align="right" style="padding:5px;">';
		if($contador == 9)	$tabla .= '<div id="masmarcas_'.$cantidad.'" style="display:block; text-align:right"><a href="javascript:showcategorias(\'marcas_'.$cantidad.'\',\'masmarcas_'.$cantidad.'\')" style="color:#DB3928; font-size:11px; text-decoration:none;">| VER MAS | +</a>&nbsp;&nbsp;&nbsp;<br></div></div><div id="marcas_' . $cantidad .'" style="display:none">';
		$tabla .= '&nbsp;&nbsp;'.$rgp->marca.'<br>';
		}
	}
	if($contador > 9) $tabla .= '<br><div style="text-align:right"><a href="javascript:showcategorias(\'masmarcas_'.$cantidad.'\',\'marcas_'.$cantidad.'\')" style="color:#DB3928; font-size:11px; text-decoration:none;">| VER MENOS | -</a>&nbsp;&nbsp;&nbsp;</div><br>';
	$tabla .= "</div></td></tr></table>";
	return $tabla;
}

$tplDet=new TplLoad;
$tplDet->display("buscador_marcas.tpl");
?>